<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="70px" :rules="rules" ref="form" :model="crud.order"
                 :disabled="crud.order.orderStatus==='PASS'">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据编码">
                <el-input  v-model="crud.order.code" disabled placeholder="系统自动生成"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="状态">
                <el-select
                  v-model="crud.order.orderStatus"
                  class="filter-item"
                  clearable
                  disabled
                  placeholder="状态"
                  size="small"
                  style="width: 100%;"
                >
                  <el-option
                    v-for="item in dict.common_order_status"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="业务日期">
                <el-date-picker
                  v-model="crud.order.busDate"
                  type="date"
                  style="width: 100%;"
                  format="yyyy - MM - dd "
                  value-format="yyyy-MM-dd"
                  default-value
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="出库仓库" prop="warehouseId">
                <zSelect :value.sync="crud.order.warehouseId" :label="crud.order.warehouseName" :disabled=" crud.order.orderStatus=='PASS'" url="api/dropDown/basWarehouseList"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="到货日期" prop="acceptDate">-->
<!--                <el-date-picker-->
<!--                  v-model="crud.order.acceptDate"-->
<!--                  type="date"-->
<!--                  style="width: 100%;"-->
<!--                  :disabled="crud.order.orderStatus==='PASS'"-->
<!--                  default-value-->
<!--                  format="yyyy - MM - dd "-->
<!--                  value-format="yyyy-MM-dd"-->
<!--                  placeholder="选择日期">-->
<!--                </el-date-picker>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="来源类型">
                <el-select
                  v-model="crud.order.sourceType"
                  class="filter-item"
                  clearable
                  disabled
                  placeholder="系统自动生成"
                  size="small"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in dict.t_buy_order_source_type"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value + ''"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="来源编号">
                <el-input   v-model="crud.order.sourceCode"  disabled  placeholder="系统自动生成"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="备注">
                <el-input  v-model="crud.order.remark"  :disabled="crud.order.orderStatus==='PASS'"  placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!--   操作栏   -->
      <div >
        <!--        <el-button-->
        <!--          slot="left"-->
        <!--          class="filter-item"-->
        <!--          size="mini"-->
        <!--          type="success"-->
        <!--          :disabled="crud.selections.length !== 1"-->
        <!--          @click="toDeatil(crud.selections)"-->
        <!--        >修改-->
        <!--        </el-button>-->
<!--        <el-button-->
<!--          slot="right"-->
<!--          class="filter-item"-->
<!--          size="mini"-->
<!--          :disabled="crud.order.orderStatus==='PASS'"-->
<!--          type="primary"-->
<!--          @click="submit()"-->
<!--          v-permission="permission.add"-->
<!--        >-->
<!--          保存-->
<!--        </el-button>-->
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          :disabled="$route.params.id=='null'"
          @click="crud.toPrint('wareSalesInvoiceDetail',crud.selections[0].id)"
        >
          <!--        v-permission="permission.reject"-->
          打印
        </el-button>
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          type="success"
          :disabled="crud.order.pickStatus != 3"
          @click="crud.toPrint('wareSalesInvoiceDetail',crud.selections[0].id)"
          v-permission="permission.pickPrint"
        >拣货单打印
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          :disabled="crud.order.pickStatus == 3|| crud.order.pickStatus == 4|| crud.order.pickStatus == 5"
          @click="packComplete(crud.selections)"
          v-permission="permission.pickEnd"
        >
          <!--        v-permission="permission.reject"-->
          拣货完成
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          :disabled="crud.order.pickStatus != 2"
          @click="collectionComplete(crud.selections)"
          v-permission="permission.checkEnd"
        >
          <!--        v-permission="permission.reject"-->
          集货完成
        </el-button>
      </div>
      <!--      :summary-method="crud.getSummaries"-->
      <div class="flex-cen">
        <div class="flex-left oldDiv">
          <el-table ref="table" row-class-name="crud.tableRowClassName"
                    height="500px"
                    :data="crud.data"
                    size="small" style="width: 100%;"
                    :show-summary="true"
                    :summary-method="crud.sumRow"
                    sortable="custom"
                    border
                    @row-click="selectRow"
                    :row-style="crud.rowClass"
                    :row-class-name="crud.tableRowClassName"
                    @sort-change="crud.sortChange"
                    @selection-change="crud.selectionChangeHandler"
                    @row-dblclick="dbClick">
            <el-table-column  type="selection" width="60" />
            <el-table-column  type="index" width="60" label="序号"/>
            <el-table-column v-if="columns.visible('goodsCode')" prop="goodsCode" label="商品编码" />
            <el-table-column  v-if="columns.visible('goodsName')" prop="goodsName" label="商品名称" width="200">
              <template slot-scope="scope">
                <span>{{ scope.row.goodsName }}</span>
<!--                <jtg-select-plus v-else ref="productRef"-->
<!--                                 v-model="scope.row.goodsId"-->
<!--                                 :initValue="scope.row.goodsName"-->
<!--                                 :productTypeId="scope.row.productTypeId"-->
<!--                                 :customerId="crud.order.customerId"-->
<!--                                 :buyChannel ="crud.order.buyChannel"-->
<!--                                 @remoteMethod="getValue($event,scope.$index)"-->
<!--                                 @input="getInput($event,name,scope.$index)"-->
<!--                                 @change="crud.productChange($event,scope)"-->
<!--                                 url="productList"/>-->
              </template>
            </el-table-column>
            <el-table-column v-if="columns.visible('barcode')" prop="barcode" label="条形码" />
            <el-table-column v-if="columns.visible('pickGoodsCount')" prop="pickGoodsCount" label="拣货数量" >
              <template slot-scope="scope">
                <span :class="{'red':(scope.row.pickGoodsCount !== scope.row.goodsCount)}">{{ scope.row.pickGoodsCount }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="columns.visible('pickBoxNum')" prop="pickBoxNum" label="拣货辅数量" >
              <template  slot-scope="scope">
                <span :class="{'red':(scope.row.pickGoodsCount !== scope.row.goodsCount)}">
                  <span >{{ scope.row.pickBoxNum }}{{ scope.row.boxUnitName }}</span>
                  <span >{{ scope.row.pickMainNum }}{{ scope.row.mainUnitName }}</span>
                </span>
              </template>
            </el-table-column>
            <el-table-column v-if="columns.visible('checkGoodsCount')" prop="checkGoodsCount" label="核对数量" >
              <template slot-scope="scope">
                <span :class="{'red':(scope.row.pickGoodsCount !== scope.row.goodsCount)}">{{ scope.row.checkGoodsCount }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="columns.visible('checkMainNum')" prop="checkMainNum" label="核对辅数量" >
              <template slot-scope="scope">
                <span :class="{'red':(scope.row.pickGoodsCount !== scope.row.goodsCount)}">
                  <span >{{ scope.row.checkBoxNum }}{{ scope.row.boxUnitName }}</span>
                  <span >{{ scope.row.checkMainNum }}{{ scope.row.mainUnitName }}</span>
                </span>
              </template>
            </el-table-column>
            <el-table-column v-if="columns.visible('goodsCount')" prop="goodsCount" label="原数量" />
            <el-table-column v-if="columns.visible('boxNum')" prop="boxNum" label="原辅数量" >
              <template slot-scope="scope">
                <span >{{ scope.row.boxNum }}{{ scope.row.boxUnitName }}</span>
                <span >{{ scope.row.mainNum }}{{ scope.row.mainUnitName }}</span>
              </template>
            </el-table-column>
            <!--            <el-table-column v-if="columns.visible('boxUnitId')" prop="boxUnitId" label="辅数量" width="300">-->
            <!--              <template slot-scope="scope">-->
            <!--                <span v-if="!scope.row.isSelected">{{ scope.row.boxNum }}{{ scope.row.boxUnitName }}</span>-->
            <!--                <el-input v-if="scope.row.isSelected"-->
            <!--                          @input.native="crud.inuptCount(scope, 'boxNum')"-->
            <!--                          v-model="scope.row.boxNum"-->
            <!--                          style="width: 45%!important;">-->
            <!--                  <template slot="append" >{{scope.row.boxUnitName}}</template>-->
            <!--                </el-input>-->
            <!--                <span v-if="!scope.row.isSelected">{{ scope.row.mainNum }}{{ scope.row.mainUnitName }}</span>-->
            <!--                <el-input v-if="scope.row.isSelected"-->
            <!--                          @input.native="crud.inuptCount(scope, 'mainNum')"-->
            <!--                          v-model="scope.row.mainNum"-->
            <!--                          style="width: 45%!important;">-->
            <!--                  <template slot="append" >{{scope.row.mainUnitName}}</template>-->
            <!--                </el-input>-->
            <!--              </template>-->
            <!--            </el-table-column>-->
<!--            <el-table-column v-if="columns.visible('taxName')" prop="taxName" label="税额" />-->
            <el-table-column v-if="columns.visible('producedDate')" prop="producedDate" label="生产日期">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.producedDate) }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="columns.visible('deadlineDate')" prop="deadlineDate" label="截止日期">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.deadlineDate) }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="columns.visible('packBoxCode')" prop="packBoxCode" label="装箱码" />
            <el-table-column v-if="columns.visible('remark')" prop="remark" label="备注"  width="200">
              <template slot-scope="scope">
                <span v-if="!scope.row.isSelected">{{ scope.row.remark }}</span>
                <el-input v-if="scope.row.isSelected"
                          type="textarea"
                          :rows="2"
                          v-model.lazy="scope.row.remark"
                          style="width: 100%"/>
              </template>
            </el-table-column>

          </el-table>
        </div>
        <div class="flex-right">
          <h1 class="flex-right-top">商品名称</h1>
          <h3 class="flex-right-tips">{{info.goodsName || '*****'}}</h3>
          <h2 class="flex-right-bt">辅数量</h2>
          <div  class="flex-right-concent">
            <span>
               <el-input
                 type="number"
                 ref="boxNum"
                 @change="changeNum"
                 :autofocus="true"
                 v-model="info.boxNum"
                 :disabled=" crud.order.pickStatus == 3|| crud.order.pickStatus == 4|| crud.order.pickStatus == 5"
                 @focus="showBoxNum == true"
               >
                  <template slot="append">{{info.boxUnitName || '打'}}</template>
               </el-input>
            </span>
            <span>
               <el-input
                 ref="mainNum"
                 type="number"
                 @change="changeNum"
                 :autofocus="true"
                 :disabled="crud.order.pickStatus == 3|| crud.order.pickStatus == 4|| crud.order.pickStatus == 5"
                 @focus="showMainNum == true"
                 v-model="info.mainNum"

               >
                    <template slot="append">{{info.mainUnitName || '箱'}}</template>
               </el-input>
            </span>
          </div>
          <div class="keysBox">

            <div

              v-for="(m,index) in keys"

              @click="clickKey(m,index)"

              :class="(index==keyIndex?'active':'' )+ (m==='' || m=='X'?'bgHs':'')"

            >

              {{m}}

            </div>

          </div>

        </div>
      </div>
    </div>
    <el-dialog  title="打印预览"
                destroy-on-close
                v-dialogDrag
                close-on-press-escape
                :visible.sync="showPdf" append-to-body width="50vw">
      <j-pdf :src="pdfSrc" ></j-pdf>
    </el-dialog>
    <!--分页组件-->
    <!--      <pagination />-->
  </div>
</template>

<script>
import crudWareSalesInvoicePick from '@/api/erp/wareSalesInvoicePick'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import jtgSelectPlus from '@/components/select/JtgSelectPlus'
import { getCompany } from '@/api/system/company'
import {Notification} from "element-ui";
// crud交由presenter持有
const defaultCrud = CRUD({ title: '拣货任务明细',
  params() {
    const href = location.href.split('/')
    return {
      id: href[href.length - 1] == 'add' ? 0 : href[href.length - 1],page:0,size: 99999
    }
  },
  url: 'api/wareSalesInvoicePick/detail',name:'crudWareSalesInvoicePick', sort: 't.seq,asc',crudMethod: { ...crudWareSalesInvoicePick }})
const defaultForm = { id: null, orderId: null, goodsId: null, goodsCode: null, goodsName: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, taxId: null, taxCode: null, taxName: null, taxRate: null, firstUnitId: null, firstUnitCode: null, firstUnitName: null, firstUnitCount: null, effectGoodsCount: null, cutOffGoodsCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, seq: null, remark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null }
export default {
  name: 'crudWareSalesInvoicePickDetail',
  components: { pagination, crudOperation, rrOperation, udOperation,jtgSelectPlus},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['t_buy_order_source_type','common_order_status',],

  data() {
    return {
      keys:[1,2,3,4,5,6,7,8,9,"切换",0,'X'],

      keyIndex:-1,
      valueList:[],
      values:null,
      maxlen: 12,
      red:['pickGoodsCount','pickBoxNum','checkGoodsCount','checkBoxNum'],
      valueLists:"",
      showPdf:false,
      pdfSrc:'',
      permission: {
        add: ['admin', 'wareSalesInvoicePick:add'],
        edit: ['admin', 'wareSalesInvoicePick:edit'],
        del: ['admin', 'wareSalesInvoicePick:del'],
        import: ['admin', 'wareSalesInvoicePick:import'],
        export: ['admin', 'wareSalesInvoicePick:export'],
        copy: ['admin', 'wareSalesInvoicePick:copy'],
        upload: ['admin', 'wareSalesInvoicePick:upload'],
        download: ['admin', 'wareSalesInvoicePick:download'],
        pass: ['admin', 'wareSalesInvoicePick:pass'],
        reject: ['admin', 'wareSalesInvoicePick:reject'],
        closed: ['admin', 'wareSalesInvoicePick:closed'],
        invalid: ['admin', 'wareSalesInvoicePick:invalid'],
        stop: ['admin', 'wareSalesInvoicePick:stop'],
        recover: ['admin', 'wareSalesInvoicePick:recover'],
        pickStart: ['admin', 'wareSalesInvoicePick:pickStart'],
        pickEnd: ['admin', 'wareSalesInvoicePick:pickEnd'],
        checkEnd: ['admin', 'wareSalesInvoicePick:checkEnd'],
        cancelPick: ['admin', 'wareSalesInvoicePick:cancelPick'],
        pickPrint: ['admin', 'wareSalesInvoicePick:pickPrint'],
        checkPrint: ['admin', 'wareSalesInvoicePick:checkPrint'],
        setPickSeq: ['admin', 'wareSalesInvoicePick:setPickSeq'],
        assignPickUser: ['admin', 'wareSalesInvoicePick:assignPickUser'],
      },
      rules: {
        deptId: [
          { required: true, message: '采购部门不能为空', trigger: 'blur' }
        ],
        acceptDate: [
          { required: true, message: '到货日期不能为空', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '采购单类型不能为空', trigger: 'blur' }
        ],
        buyChannel: [
          { required: true, message: '渠道类型不能为空', trigger: 'blur' }
        ],
        // sourceType: [
        //   { required: true, message: '来源类型不能为空', trigger: 'blur' }
        // ],
        customerId: [
          { required: true, message: '供应商不能为空', trigger: 'blur' }
        ],
        userId: [
          { required: true, message: '业务员不能为空', trigger: 'blur' }
        ],
        isAppend: [
          { required: true, message: '是否追加不能为空', trigger: 'blur' }
        ],
        isContact: [
          { required: true, message: '是否第三方采购不能为空', trigger: 'blur' }
        ],
      },
      addRowData:{
        isSelected: true,id: null, orderId: null, goodsId: null, goodsCode: null, goodsName: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, taxId: null, taxCode: null, taxName: null, taxRate: null, firstUnitId: null, firstUnitCode: null, firstUnitName: null, firstUnitCount: null, effectGoodsCount: null, cutOffGoodsCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, seq: null, remark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null
      },
      productList:[],
      mainNum: '',
      showBoxNum: true,
      showMainNum: false,
      boxNum: '',
      selectedArrData: [],
      info: {
        mainUnitName: '',
        boxUnitName: '',
        boxNum: null,
        mainNum: null,
        goodsName: ''
      }

    }
  },
  watch:{

    // value(newVal){
    //
    //   this.values=newVal
    //
    // },

    valueList(newVal){

      this.valueLists=newVal;

    },
    crud: function() {
      this.$nextTick(function() {
        this.$refs.table.setCurrentRow(this.crud.data[0]);
        //触发第一行选中事件
        this.handleClick(this.crud.data[0]);
      });
    }

  },

  mounted(){

    this.values=this.value;

    if(this.valueList){

      this.valueLists=this.valueList;

    }else{

      this.valueLists="";

    }

  },
  destroyed() {
    this.crud.setItemInfo("wareBuyReturnPickDetail_add")
  },
  created(){
    if (this.$route.params.id == 'add') {
      if( this.crud.getItemInfo("wareBuyReturnPickDetail_add")){
        return false
      }
      this.crud.order = {
        id: null,
        code: '',
        busDate:  this.getTime(),
        // createTime: this.getTime(),
        name: '',
        carId: null,
        userId: '',
        deptId: null,
        type: null,
        acceptDate: null,
        isContact: null,
        isAppend: null,
        orderStatus: 'SAVE',
        index: '0',
        customerId:'',
        contactName:'',
        contactPhone:'',
        startDate: null,
        endDate: null,
        remark: '',
      }
      // this.crud.data.push(JSON.parse(JSON.stringify(this.addRowData)))
    }
  },
  beforeUpdate() {
    if (this.$route.params.id != 'add') {
      this.id = this.$route.params.id
      this.query.id = this.id
      this.crud.order.id = this.id

    }
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    dbClick(){
      this.clickKey('切换')
      this.crud.dbClick()
    },
    selectRow(row, column, event) {
      console.log('row',row,column,event)
      this.info = JSON.parse(JSON.stringify(row))
      this.info.mainNum = row.pickMainNum
      this.info.boxNum = row.pickBoxNum
      if(this.info.boxNum&&!this.info.mainNum){
        this.showMainNum = true
        this.showBoxNum = false
        this.$refs.mainNum.focus()
      }else{
        this.showMainNum = false
        this.showBoxNum = true
        this.$refs.boxNum.focus()
      }
      this.crud.selectRow()
      this.clickKey('切换')
    },
    yzmTitleClick(){

      this.$emit('keyChange',this.valueLists)

    },
    changeNum(){
      this.info.mainNum = this.info.mainNum || 0
      this.info.boxNum = this.info.boxNum || 0
      this.crud.data[this.info.index].pickMainNum = this.info.mainNum
      this.crud.data[this.info.index].pickBoxNum = this.info.boxNum
      this.crud.data[this.info.index].checkMainNum = this.info.mainNum
      this.crud.data[this.info.index].checkBoxNum = this.info.boxNum
      this.crud.data[this.info.index].checkGoodsCount = this.info.boxNum * Number(this.crud.data[this.info.index].boxUnitCount || 0) + Number(this.info.mainNum)
      this.crud.data[this.info.index].pickGoodsCount = this.info.boxNum * Number(this.crud.data[this.info.index].boxUnitCount || 0) + Number(this.info.mainNum)
      this.crud.data[this.info.index].boxNum =  this.boxNum
      this.crud.data[this.info.index].mainNum =  this.mainNum
      this.$set(this.crud.data, this.info.index, this.crud.data[this.info.index])

      if( this.crud.data[this.info.index].pickGoodsCount >  this.crud.data[this.info.index].goodsCount){
        this.crud.data[this.info.index].pickMainNum = 0
        this.crud.data[this.info.index].pickBoxNum = 0
        this.crud.data[this.info.index].checkMainNum = 0
        this.crud.data[this.info.index].checkBoxNum = 0
        this.crud.data[this.info.index].checkGoodsCount = 0
        this.crud.data[this.info.index].pickGoodsCount = 0
        this.info.mainNum = 0
        this.info.boxNum = 0
        this.$set(this.crud.data, this.info.index, this.crud.data[this.info.index])
        this.$message({
          type: 'error',
          message: '拣货数量不能大于原数量!'
        });
        return  false
      }
    },
    clickKey(m,ind){
      console.log('values',this.info.goodsName)
      if(!this.info.goodsName){
        this.$message({
          type: 'error',
          message: '请先选择一条数据!'
        });
        return false
      }
      if(this.showMainNum){
        this.$refs.mainNum.focus()
      }else{
        this.$refs.boxNum.focus()
      }
      if(m==="" || m==undefined){

        return

      }else{

        if(m=='X'){

          this.clickStyle(ind)
          if(this.showMainNum){
            this.info.mainNum= this.info.mainNum.length == undefined ? '' :this.info.mainNum.substr(0,this.info.mainNum.length-1)
          }else{
            this.info.boxNum=this.info.boxNum.length == undefined ? '' :this.info.boxNum.substr(0,this.info.mainNum.length-1)
          }

        }else if(m=='切换'){
          if(this.showMainNum){
            this.showMainNum = false
            this.showBoxNum = true
            this.$refs.boxNum.focus()
          }else{
            this.showMainNum = true
            this.showBoxNum = false
            this.$refs.mainNum.focus()
          }
          console.log('mainNum',this.info.mainNum )
          console.log('boxNum',this.info.boxNum )
        }else{
          this.clickStyle(ind)
          if(this.showMainNum){
            this.info.mainNum=(this.info.mainNum == 0?'':this.info.mainNum) +'' + m
          }else{
            this.info.boxNum=(this.info.boxNum == 0?'':this.info.boxNum)+'' + m
          }




        }

        this.crud.data[this.info.index].pickMainNum = this.info.mainNum
        this.crud.data[this.info.index].pickBoxNum = this.info.boxNum
        this.crud.data[this.info.index].checkMainNum = this.info.mainNum
        this.crud.data[this.info.index].checkBoxNum = this.info.boxNum
        this.crud.data[this.info.index].checkGoodsCount = this.info.boxNum * Number(this.crud.data[this.info.index].boxUnitCount || 0) + Number(this.info.mainNum)
        this.crud.data[this.info.index].pickGoodsCount = this.info.boxNum * Number(this.crud.data[this.info.index].boxUnitCount || 0) + Number(this.info.mainNum)
        this.crud.data[this.info.index].boxNum =  this.boxNum
        this.crud.data[this.info.index].mainNum =  this.mainNum
        this.$set(this.crud.data, this.info.index, this.crud.data[this.info.index])

      }



    },

    clickStyle(ind){

      this.keyIndex=ind;

      setTimeout(()=>{

        this.keyIndex=-1

      },300)

    },


    // 开始拣货
    packComplete(e){
      this.crud.order.detailList  = this.crud.data
      let params = this.crud.order
      this.crud.loadingOpen()
      crudWareSalesInvoicePick.pickEnd(params).then(res => {
        this.$message({
          type: 'success',
          message: '拣货成功!'
        });
        this.crud.loadingClose()
        this.crud.toQuery()
      }).catch((res)=>{
        this.crud.loadingClose()
      })
    },
    collectionComplete(e){
      this.crud.order.detailList  = this.crud.data
      let params = this.crud.order
      this.crud.loadingOpen()
      crudWareSalesInvoicePick.checkEnd(params).then(res => {
        this.$message({
          type: 'success',
          message: '集货成功!'
        });
        this.crud.loadingClose()
        this.crud.toQuery()
      }).catch((res)=>{
        this.crud.loadingClose()
      })
    },
    getInfo(e){
      this.crud.order.warehouseId = e.warehouseId
      this.crud.order.deptId = e.deptId
      this.crud.order.deptId = e.deptId
      this.crud.order.userId = e.userId
    },
    delAddRow(i){
      if(this.$route.params.id !== 'add'){
        this.$confirm('此操作将直接删除此条产品记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.crud.delRow(i)
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }else{
        this.crud.delRow(i)
      }
    },
    getValue(e,i){
      console.log('this.crud.data',this.crud.data )
      this.crud.data[i].productName = e
      // let temp = this.crud.data[2]
      // this.crud.data[3] = temp
      this.crud.data.map(item => {
        // item.existId = 0
        // item.existNum = 0
        if(item.existBox === null){
          item.existBox = 0
        }
        if(item.occupyBox === null){
          item.occupyBox = 0
        }
      })
    },
    getInput(e,name,i){
      console.log(',data.goodsName',e,name,i)
      if(this.crud.data){
        if(e){
          this.crud.data[i].goodsName = ''
          this.crud.data[i].goodsId= e
        }else{
          this.crud.data[i].goodsName = ''
          this.crud.data[i].goodsId= null
        }
      }
    },
    // 保存
    submit(){
      var oDate1 = new Date(this.crud.order.startDate);
      var oDate2 = new Date(this.crud.order.endDate);
      if(oDate1.getTime() > oDate2.getTime()){
        this.$message({
          message: '开始日期不能大于结束日期',
          type: 'warning'
        })
        this.crud.order.startDate = null
        this.crud.order.endDate = null
        return false
      }
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        const table_rules = [
          // {name: '数量', value: 'goodsCount'},
          // {name: '采购价', value: 'taxPrice'},
          // {name: '未税单价', value: 'noTaxPrice'},
          // {name: '含税金额', value: 'taxAmount'},
          // {name: '未税金额', value: 'noTaxAmount'}
        ]
        const result = table_rules.some(({name, value}) => {
          const rules = this.$refs.table.data.some((item, index) => {
            if (!this.tableRules((index + 1), name, item[value])) return true
          })
          if (rules) return true
        })
        if (!result) this.save()
      })
    },
    tableRules(index, name, value) {
      if (!value) {
        Notification.error({title: '序号【' + index + '】' + name + '不能为空'})
        return false
      } else return true
    },
    getTime(date = new Date()){
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? ('0' + m) : m;
      var d = date.getDate();
      d = d < 10 ? ('0' + d) : d;
      var h = date.getHours();
      h=h < 10 ? ('0' + h) : h;
      var minute = date.getMinutes();
      minute = minute < 10 ? ('0' + minute) : minute;
      var second=date.getSeconds();
      second=second < 10 ? ('0' + second) : second;
      // +' '+h+':'+minute+':'+second;
      return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second
    },
    //保存
    save() {
      let that = this
      that.crud.loadingOpen()
      this.crud.order.detailList  = this.crud.data
      let params = this.crud.order
      crudWareSalesInvoicePick.add(params).then(res => {
        if(res.success){
          this.crud.order  = res.data
          // this.crud.data = res.data.detailList
          let id=res.data.id
          if(this.$route.params.id == 'add'){
            this.$store.dispatch("tagsView/delView", this.$route);
            this.$router.push({params: {id}})
            this.crud.cleanItemInfo('wareSalesInvoicePickDetail_add')
          }
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          that.crud.loadingClose()
        }else{
          that.crud.loadingClose()
          this.$message({
            message: res.msg,
            type: 'warning'
          })
        }

      }).catch((res)=>{
        that.crud.loadingClose()
      })
    },
    //修改
    toDetail(){
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

  }
}
</script>

<style lang="scss" scoped>
.el-table__row:hover > td {
  background-color: transparent!important;
}
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
.flex-cen{
  display: flex;
  align-items: self-start;
  justify-content: space-between;
}
.flex-left{
  width: 75%;
}
.flex-right{text-align: center;
  width: 21%;
  min-width: 350px;
  height: 480px;
  position: relative;
  background: #fdfdfd;
  /*border-top: 1px solid #DDDDDD;*/
  /*border-left:  1px solid #DDDDDD;*/
  box-shadow: 5px 5px 5px #DDDDDD;
}
</style>

<style lang="scss" scoped>
/* 用来设置当前页面element全局table 选中某行时的背景色*/
.el-table__body tr.current-row>td{
  background-color: #ddf1ff !important;
  color: #fff;
}
.el-input__inner:focus{

  border-color:#ddf1ff!important;

}
.el-input__inner:focus{
  border:1px solid #ddf1ff;
}
.flex-right-concent{
  width: 100%;
  display: flex;
  align-items: self-start;
  justify-content: space-between;
  span{
    width: 48%;
    margin: 0 2%;
  }
}
.yzmTitle{

  height: 30px;

  font-size: 16px;

  color: #333;

  text-align: center;

}

.keysBox{
  width: 100%;
  position:absolute;
  left: 0;
  bottom: 0;
  //height: 400px;
}

.keysBox>div{

  width: 33.33%;

  height: 50px;

  line-height: 50px;

  text-align: center;

  float: left;

  border: 1px solid #f5f5f5;

  box-sizing: border-box;

}


.active{

  background: #eee;

  color: #333333;

}
.bgHs{

  background: #eee;

}
.red{
  color: red;
}


</style>
